package cfgs.gestudent.main;

import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import cfgs.gestudent.finestra.main.FinestraPrincipal;
import cfgs.gestudent.finestra.preferencies.FinestraPreferenciesServidorInici;
import cfgs.gestudent.models.EntitatSerivodBBDD;
import cfgs.gestudent.preferencies.ConfiguracionsIdiomes;
import cfgs.gestudent.preferencies.PreferenciesServidor;
/**
 * 
 * @author Jaume Alberti Llompart
 *
 */
public class TestGeStudent {
	
	//TODO Falta traduir a ingles
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ConfiguracionsIdiomes conf = new ConfiguracionsIdiomes();
					ResourceBundle rb = conf.getIdioma();
					
					Connection connexio = null;
					PreferenciesServidor ps = new PreferenciesServidor();
					EntitatSerivodBBDD esbd = ps.getParametre();
					
					String server = esbd.getServidor();
					String port = esbd.getPort();
					String nameDB = esbd.getNomBD();
					String user = esbd.getUsuari();
					String password = esbd.getPassword();
					
					try {
						Class.forName("com.mysql.jdbc.Driver");
						connexio = DriverManager.getConnection("jdbc:mysql://"+server+":"+port+"/"+nameDB, user, password);
					} catch(SQLException e){
						JOptionPane.showMessageDialog(null, rb.getString("missatgeConexioIncorrecta"), rb.getString("titolConexioIncorrecta"), JOptionPane.ERROR_MESSAGE);
					}catch(ClassNotFoundException e){
						JOptionPane.showMessageDialog(null, rb.getString("missatgeErrorDriver"), rb.getString("titolErrorDriver"), JOptionPane.ERROR_MESSAGE);
					}
					
					
					if(connexio == null){
						FinestraPrincipal fp = new FinestraPrincipal();
						
						FinestraPreferenciesServidorInici fpsi = new FinestraPreferenciesServidorInici();
						fpsi.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
						fpsi.setVisible(true);
						
					}else{
						FinestraPrincipal fp = new FinestraPrincipal();
					}
					/*
					FinestraLog dialog = new FinestraLog();
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);*/
										
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}


}
